import numpy as np
import pandas as pd
from sklearn.metrics import roc_auc_score
import time
import os
import sys
from sklearn import metrics


def run_process(response,l0,trans,guess,slip):
	predict = []
	for index in range(len(response)):
		pc_t = (1-slip)*l0 + guess*(1-l0)          # 下次答对的概率
		predict.append(pc_t)

		if(response[index] == 1):
		    p_t_obs= l0*(1-slip)/(l0*(1-slip)+(1-l0)*guess)
		    l0 = p_t_obs +(1-p_t_obs)*trans

		if(response[index] == 0):
			p_t_obs = l0*slip/(l0*slip+(1-l0)*(1-guess))
			l0 = p_t_obs + (1-p_t_obs)*trans
		

	return predict



def lable(x):
	if (x>=0.5):
		return 1
	else:
	    return 0

data = pd.read_csv('english.csv')
student = data['s_id'].unique()
error = 0
total = 0

all_origin = []
all_predict = []
for s_id in student:
	item = data[(data['s_id'] == s_id)]
	origin = list(item.correct.values)
	predict = run_process(item.correct.values,0.517,0.0255,0.434,0.205)
	all_origin.extend(origin)
	all_predict.extend(predict)

print ("size:",len(all_origin))
print (roc_auc_score(all_origin, all_predict))
all_predict = list(map(lable,all_predict))
print (metrics.accuracy_score(all_origin, all_predict))
auc = metrics.confusion_matrix(all_origin,all_predict)
print (auc)

